using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Soundmgr : MonoBehaviour
{
    private static Soundmgr instance;

    public static Soundmgr Instance;

    private AudioSource audioSource;

    private void Awake()
    {
        Instance = this;
    }
    private void Start()
    {

        audioSource = gameObject.AddComponent<AudioSource>();
        audioSource.playOnAwake = false;
    }


    private void PlayAudio(AudioClip ac,Vector3 pos,float vol)
    {
        AudioSource.PlayClipAtPoint(ac, pos, vol);
    }


    public void PlayMusicByName (string name,Vector3 pos,float vol)
    {
        string path = "Sounds/" + name;
        AudioClip clip = Resources.Load<AudioClip>(path);
        PlayAudio(clip,pos,vol);
    }

    public void StopMusic()
    {
        audioSource.Stop();
    }
}
